<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/mui.js"></script>
		<script src="./utils/myRequest.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function(){
				// var check = true;
				// mui(".mui-input-group input").each(function () {
				//   //若当前input为空，则alert提醒
				//   if(!this.value||trim(this.value)==""){
				//     var label = this.previousElementSibling;
				//     mui.alert(label.innerText+"不允许为空");
				//     check = false;
				//     return false;
				//   }
				// });
				// //校验通过，继续执行业务逻辑
				// if(check){
				//   mui.alert("条件成立");
				// }
				
				//获取参数值
				document.getElementById("btnRgister").addEventListener('tap',function(){
					var username = document.getElementById("username").value;
					var nickname = document.getElementById("nickname").value;
					var phone = document.getElementById("phone").value;
					var password = document.getElementById("password").value;
					
					var param = new Object();
					param.username = username;
					param.nickname = nickname;
					param.phone = phone;
					param.password = password;
					
					//将数据提交到后台
					// plus.nativeUI.toast(JSON.stringify(param));
					console.log(JSON.stringify(param));
					
					request.ajax({
						url : "/websocket/user/register",
						data : param,
						type : "post",
						success:function(resp){
							//服务器返回响应，根据响应结果，分析是否登录成功；
							// console.log(JSON.parse(resp));
							// console.log(resp);
							// var obj = JSON.parse(resp);
							if(resp.code == 20000){
								plus.nativeUI.toast(resp.message);
								//注册成功
								//回到登录页面
								plus.webview.open("./login.html","login.html");
								//关闭当前页面
								plus.webview.currentWebview().close();
							}else{
								plus.nativeUI.toast(resp.message);
							}
						}
						
					})
					
					// mui.ajax('http://192.168.2.216:8160/websocket/user/register',{
					// 	data:param,
					// 	dataType:'json',//服务器返回json格式数据
					// 	type:'post',//HTTP请求类型
					// 	timeout:10000,//超时时间设置为10秒；
					// 	headers:{'Content-Type':'application/json'},	              
					// 	success:function(resp){
					// 		//服务器返回响应，根据响应结果，分析是否登录成功；
					// 		// console.log(JSON.parse(resp));
					// 		// console.log(resp);
					// 		// var obj = JSON.parse(resp);
					// 		if(resp.code == 20000){
					// 			plus.nativeUI.toast(resp.message);
					// 			//注册成功
					// 			//回到登录页面
					// 			plus.webview.open("./login.html","login.html");
					// 			//关闭当前页面
					// 			plus.webview.currentWebview().close();
					// 		}else{
					// 			plus.nativeUI.toast(resp.message);
					// 		}
					// 	},
					// 	error:function(xhr,type,errorThrown){
					// 		//异常处理；
					// 		console.log(type);
					// 		plus.nativeUI.toast(type);
					// 	}
					// });
					
				})
			})
		</script>
	</head>

	<body>
		<!-- <h1>注册页面</h1> -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">新用户</h1>
		</header>
		
		<div style="margin-top: 50px;">
			<!-- 表单 -->
			<div class="mui-input-group">
			    <div class="mui-input-row">
			        <label>用户名</label>
			    <input type="text" class="mui-input-clear" id="username" placeholder="请输入用户名">
			    </div>
				<div class="mui-input-row">
				    <label>昵 称</label>
				<input type="text" class="mui-input-clear" id="nickname" placeholder="请输入昵称">
				</div>
				<div class="mui-input-row">
				    <label>手机号</label>
				<input type="text" class="mui-input-clear" id="phone" placeholder="请输入手机号">
				</div>
			    <div class="mui-input-row">
			        <label>密 码</label>
			        <input type="password" class="mui-input-password" id="password" placeholder="请输入密码">
			    </div>
			    <div class="mui-button-row">
			        <button type="button" id="btnRgister" class="mui-btn mui-btn-primary" >注册</button>
			        <button type="button" class="mui-btn mui-btn-danger" >取消</button>
			    </div>
			</div>
		</div>
	</body>

</html>
